package com.zhangxx.web.common.util;

import com.zhangxx.web.common.exception.BusinessException;
import com.zhangxx.web.common.model.ServerStatus;
import org.springframework.validation.BindingResult;

public class ValidUtils {
    /**
     *
     * @apiNote  功能描述 : 参数效验
     * @author zhangbo
     * @date 2019/3/26

     * @param bindingResult BindingResult
     */
    public static void paramsValid(BindingResult bindingResult) {
        if(bindingResult.hasErrors()){
            bindingResult.getFieldErrors().forEach(fieldError->{
                throw new BusinessException(ServerStatus.VALIDATION_ERROR.value(),fieldError.getDefaultMessage());
            });
        }
    }
}
